package com.zhuiyun.project.api.appuser.controller;

import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.appuser.entity.User;
import com.zhuiyun.project.api.appuser.model.AppUserModel;
import com.zhuiyun.project.api.appuser.service.impl.AppUserServiceImpl;
import com.zhuiyun.project.api.articlereport.model.ReportModel;
import com.zhuiyun.project.api.sysarticle.model.ArticleModel;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.util.constants.CommonConstants;
import com.zhuiyun.project.util.pageUtil.PageRequest;
import com.zhuiyun.project.util.pageUtil.PageResult;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName AppUserController
 * Description T0D0
 * Author Administrator
 * @Date 2023/6/8
 * Version 1.0
 **/

@RestController
@RequestMapping("/userRules")
@CrossOrigin
public class AppUserController {
    @Autowired
    AppUserServiceImpl appuserServiceImpl;

    /**
     * 通过用户名获取用户信息
     *
     * @return com.zhuiyun.project.common.response.CommonResult
     * @author 温
     * @date 2023/6/5 17:56
     * @parameter [nickName, pageRequest]
     */
    @GetMapping("/userList")
    @ApiOperation(value = "用户管理查询")
    @OptLog(modular = "用户管理", type = CommonConstants.SELECT, describe = "用户查询")
    public CommonResult userList(String userName, PageRequest pageRequest) throws CommonException {
        // 调用分页方法
        PageResult PageResult = appuserServiceImpl.userList(userName, pageRequest);
        return CommonResult.ok(PageResult);
    }


    /**
     * @param id
     * @Author kdj
     * @Description 用户查询
     * @Date 2023/7/20 21:36
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/userMain")
    public CommonResult userMain(int id) {
        return CommonResult.ok(appuserServiceImpl.userMain(id));
    }



    /**
     * @Author 小江
     * @Description //TODO 手机号去重
     * @Date 15:06 2023/8/11
     **/
    @GetMapping("/userTitle")
    @ApiOperation(value = "菜单管理的菜单描述查重方法")
    @OptLog(modular = "菜单管理", type = CommonConstants.SELECT, describe = "菜单描述查重")
    public CommonResult userTitle(String userPhone ) throws CommonException {
        return appuserServiceImpl.userTitle(userPhone);
    }



    /**
     * 用户禁言
     *
     * @return com.zhuiyun.project.common.response.CommonResult
     * @author 温
     * @date 2023/6/5 20:52
     * @parameter [id]
     */
    @PostMapping("/updateSilencedState")
    @ApiOperation(value = "修改审核标识 用户禁言")
    @OptLog(modular = "用户管理", type = CommonConstants.UPDATE, describe = "用户禁言")
    public CommonResult updateSilencedState(@RequestBody User appuser) {
        int i = appuserServiceImpl.logOffList(appuser);
        return CommonResult.ok(i);
    }


    /**
     * 根据前端传来的id 和 注销原因 来进行注销
     *
     * @return com.zhuiyun.project.common.response.CommonResult
     * @author 温
     * @date 2023/6/20 16:36
     * @parameter [cancellationId, cancellationReason]
     */
    @GetMapping("/useradd")
    @ApiOperation(value = "修改审核标识 用户注销")
    @OptLog(modular = "用户管理", type = CommonConstants.UPDATE, describe = "用户注销")
    public CommonResult useradd(Integer cancellationId, String cancellationReason) {
        int useradd = appuserServiceImpl.useradd(cancellationId, cancellationReason);
        return CommonResult.ok(useradd);
    }
    /**
    * @Author Root
    * @Description 小程序中的注销用户
    * @Date 2023/7/26 19:26
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param map
    */
    @PostMapping("/userLogout")
    public CommonResult userLogout(@RequestBody Map map){
        //将前端传递的数据在map中取出
        Integer cancellationId = Integer.valueOf(map.get("cancellationId").toString());
        String cancellationReason = map.get("cancellationReason").toString();
        int useradd = appuserServiceImpl.useradd(cancellationId, cancellationReason);
        if(useradd>0){
            return CommonResult.ok(useradd);
        }else{
            return CommonResult.error();
        }
    }


//    /**
//     * 彻底删除注销的用户
//     *
//     * @return
//     * @author 温
//     * @date 2023/6/15 8:51
//     * @parameter
//     */
//    @DeleteMapping("/userDelete")
//    @ApiOperation(value = " 彻底删除注销的用户")
//    @OptLog(modular = "用户注销管理", type = CommonConstants.DELETE, describe = "彻底删除注销的用户")
//    public CommonResult userDelete(int id) {
//        int i = appuserServiceImpl.userDelete(id);
//        return CommonResult.ok(i);
//    }

    /**
     * @param id
     * @Author kdj
     * @Description 根据userId获取头像
     * @Date 2023/7/18 20:59
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/getAvatarId")
    @ApiOperation(value = "根据userId获取头像")
    @OptLog(modular = "用户管理", type = CommonConstants.SELECT, describe = "根据userId获取头像")
    public CommonResult getAvatarId(Integer id) {
        int i = appuserServiceImpl.getAvatarId(id);
        return CommonResult.ok(i);
    }

    /**
     * @param user
     * @Author kdj
     * @Description 修改请求好友的未读数
     * @Date 2023/7/21 16:40
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @PutMapping("/upFriendNewNum")
    @ApiOperation(value = "修改请求好友的未读数")
    @OptLog(modular = "用户查询", type = CommonConstants.UPDATE, describe = "修改请求好友的未读数")
    public CommonResult upFriendNewNum(@RequestBody User user) {
        return CommonResult.ok(appuserServiceImpl.upFriendNewNum(user.getId(), user.getFriendNewNum()));
    }
    /**
     * @param userId
     * @Author 杨珅
     * @Description 拉黑用户
     * @Date 2023/7/21 16:40
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @DeleteMapping("/toProhibition")
    @ApiOperation(value = "拉黑用户")
    @OptLog(modular = "拉黑用户", type = CommonConstants.UPDATE, describe = "拉黑用户")
    public CommonResult toProhibition(Integer userId) {
        return CommonResult.ok(appuserServiceImpl.toProhibition(userId));
    }
    /**
     * @param userId
     * @Author 杨珅
     * @Description 解封用户
     * @Date 2023/7/21 16:40
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @DeleteMapping("/openProhibition")
    @ApiOperation(value = "解封用户")
    @OptLog(modular = "解封用户", type = CommonConstants.UPDATE, describe = "解封用户")
    public CommonResult openProhibition(Integer userId) {
        return CommonResult.ok(appuserServiceImpl.openProhibition(userId));
    }
    /**
     * @param id
     * @Author kdj
     * @Description 根据userId获取头像
     * @Date 2023/7/18 20:59
     * @Return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/selectUserProhibition")
    @ApiOperation(value = "根据userId获取头像")
    @OptLog(modular = "用户管理", type = CommonConstants.SELECT, describe = "根据userId获取头像")
    public CommonResult selectUserProhibition( String userPhone) {
        return CommonResult.ok(appuserServiceImpl.selectUserProhibition(userPhone));
    }
}



